home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / PowerPlant / LCicnCheck / LCicnCheck.cp next >
Encoding:
Text File  |  1996-08-12  |  3.7 KB  |  153 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    LCicnCheck.cp               ©1996 Gregory S. Combs <combs@io.com>
  3. //                                
  4. // ===========================================================================
  5. //
  6. //    An LCicnButton that works as a checkbox.
  7. //
  8. //    (License mumbo-jumbo "borrowed" from Christophe ANDRES, chrisoft@calva.net)
  9. //
  10. //    You may use this source code in any application (commercial, shareware, freeware,
  11. //    postcardware, etc), but not remove this notice (no need to acknowledge the use of
  12. //    this class in the about box)
  13. //    You may not sell this source code in any form. This source code may be placed on 
  14. //    publicly accessable archive sites and source code disks. It may not be placed on 
  15. //    profit archive sites and source code disks without the permission of the author, 
  16. //    Gregory S. Combs.
  17. //    
  18. //        This source code is distributed in the hope that it will be useful,
  19. //        but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. //        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  21. //
  22. //    If you make any change or improvement on this class, please send the improved/changed
  23. //    version to : combs@io.com
  24. //
  25.  
  26. #ifdef PowerPlant_PCH
  27. #include PowerPlant_PCH
  28. #endif
  29.  
  30. #include "LCicnCheck.h"
  31. #include <LStream.h>
  32. #include <UDrawingState.h>
  33.  
  34.  
  35. // ---------------------------------------------------------------------------
  36. //        • CreateCicnCheckStream
  37. // ---------------------------------------------------------------------------
  38. //    Create a new CicnCheck object from the data in a Stream
  39.  
  40. LCicnCheck*
  41. LCicnCheck::CreateCicnCheckStream(
  42.     LStream    *inStream)
  43. {
  44.     return (new LCicnCheck(inStream));
  45. }
  46.  
  47.  
  48. // ---------------------------------------------------------------------------
  49. //        • LCicnCheck
  50. // ---------------------------------------------------------------------------
  51. //    Default Constructor
  52.  
  53. LCicnCheck::LCicnCheck()
  54. {
  55.     SetMaxValue(1);
  56. }
  57.  
  58.  
  59. // ---------------------------------------------------------------------------
  60. //        • LCicnCheck(const LCicnButton&)
  61. // ---------------------------------------------------------------------------
  62. //    Copy Constructor
  63.  
  64. LCicnCheck::LCicnCheck(
  65.     const LCicnCheck    &inOriginal)
  66.         : LCicnButton(inOriginal)
  67. {
  68.     SetMaxValue(1);
  69. }
  70.  
  71.  
  72.  
  73. // ---------------------------------------------------------------------------
  74. //        • LCicnCheck(LStream*)
  75. // ---------------------------------------------------------------------------
  76. //    Construct a new CicnCheck from the data in a Stream
  77. //
  78.  
  79. LCicnCheck::LCicnCheck(
  80.     LStream    *inStream)
  81.         : LCicnButton(inStream)
  82. {
  83.  
  84.     SetMaxValue(1);
  85.     if ((GetValue() != 1) && (GetValue() != 0)) {
  86.         SetValue(1);
  87.     }
  88. }
  89.  
  90.  
  91. // ---------------------------------------------------------------------------
  92. //        • ~LCicnCheck
  93. // ---------------------------------------------------------------------------
  94. //    Destructor
  95.  
  96. LCicnCheck::~LCicnCheck()
  97. {
  98.  
  99. }
  100.  
  101.  
  102.  
  103. // ---------------------------------------------------------------------------
  104. //        • DrawSelf
  105. // ---------------------------------------------------------------------------
  106. //    Draw the CicnCheck
  107.  
  108. void
  109. LCicnCheck::DrawSelf()
  110. {
  111.     Rect    frame;
  112.     StColorPenState    theState;
  113.     
  114.     CalcLocalFrameRect(frame);
  115.     
  116.     theState.Normalize();
  117.     
  118.     if ( GetValue() == 1 ) {
  119.         if (mPushedCicnH == nil) {        // Load 'cicn' if necessary
  120.             mPushedCicnH = ::GetCIcon(mPushedID);
  121.         }
  122.         
  123.         if (mPushedCicnH != nil) {
  124.             ::PlotCIcon(&frame, mPushedCicnH);
  125.         }
  126.     }
  127.     else if ( GetValue() == 0 ) {
  128.         if (mNormalCicnH == nil) {        // Load 'cicn' if necessary
  129.             mNormalCicnH = ::GetCIcon(mNormalID);
  130.         }
  131.         
  132.         if (mNormalCicnH != nil) {
  133.             ::PlotCIcon(&frame, mNormalCicnH);
  134.         }
  135.     }
  136. }
  137.  
  138. void
  139. LCicnCheck::HotSpotResult(
  140.     short    inHotSpot)
  141. {    
  142.     LCicnButton::HotSpotResult( inHotSpot );
  143.     if (GetValue() == 1)
  144.         SetValue(0);
  145.     else if (GetValue() == 0)
  146.         SetValue(1);
  147.     else
  148.         SetValue(1);
  149.         
  150.     Refresh();    
  151.  
  152. }
  153.